﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _003_PythonWithParamTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //SigmaAldrich();

            HtmlRequest();
        }

        private static void HtmlRequest()
        {
            string url = "https://www.runoob.com/";

            string curPath = AppDomain.CurrentDomain.BaseDirectory;

            string path = $@"HtmlRequest.py {url}";// 待处理python文件的路径

            path = curPath + @"..\..\" + path;

            PrintPy(path);
        }

        private static void SigmaAldrich()
        {
            string productNumber = "270709";
            string brandKey = "SIGALD";

            string curPath = AppDomain.CurrentDomain.BaseDirectory;

            string path = $@"SigmaAldrich_PriceRequest.py {productNumber} {brandKey}";// 待处理python文件的路径

            path = curPath + @"..\..\" + path;

            PrintPy(path);
        }

        private static void PrintPy(string cmdStr)
        {
            Process CmdProcess = new Process();

            CmdProcess.StartInfo.FileName = "cmd.exe";

            CmdProcess.StartInfo.CreateNoWindow = true; // 不创建新窗口

            CmdProcess.StartInfo.UseShellExecute = false; //不启用shell启动进程

            CmdProcess.StartInfo.RedirectStandardInput = true; // 重定向输入

            CmdProcess.StartInfo.RedirectStandardOutput = true; // 重定向标准输出

            CmdProcess.StartInfo.RedirectStandardError = true; // 重定向错误输出

            CmdProcess.StartInfo.Arguments = "/c " + cmdStr;//“/C”表示执行完命令后马上退出

            CmdProcess.Start();//执行

            StreamReader reader = CmdProcess.StandardOutput;

            StringBuilder str = new StringBuilder();
            while (!reader.EndOfStream)
            {
                str.Append(reader.ReadLine());
            }
            reader.Close();
            Console.WriteLine(str);
            Console.WriteLine("输出结束");
            Console.ReadKey();
        }
    }
}
